/*
   Copyright 2011 
   
   DIFED

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package difed.restaurante;

import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import difed.restaurante.util.CustomLog;
import difed.restaurante.util.Notes;
import difed.restaurante.util.PubliUtil;

public class MisRestaurantes extends Activity implements
        DialogInterface.OnCancelListener {

    @Override
    public void onCancel(DialogInterface arg0) {
        // TODO Auto-generated method stub

    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        CustomLog.debug("MisRestaurantes", "onCreate");
        setContentView(R.layout.principal);
        
        Notes.show(this);

        Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/fuente.ttf");
        TextView textView = (TextView) findViewById(R.id.titulo);
        textView.setTypeface(tf);

        Typeface tf2 = Typeface.createFromAsset(getAssets(),
                "fonts/legrand.ttf");
        textView = (TextView) findViewById(R.id.t_ayuda);
        textView.setTypeface(tf2);
        textView = (TextView) findViewById(R.id.t_editar);
        textView.setTypeface(tf2);
        textView = (TextView) findViewById(R.id.t_nuevo);
        textView.setTypeface(tf2);
        textView = (TextView) findViewById(R.id.t_expimp);
        textView.setTypeface(tf2);

        // Creamos la carpeta si no existe
        File file=new File("sdcard/restaurant/");
        if(!file.exists())
            file.mkdirs();
        
        
        PubliUtil.createBanner(this, (ViewGroup) findViewById(R.id.publicidad));
       

    }
    
    protected void onDestroy() {
        PubliUtil.removeBanner((ViewGroup) findViewById(R.id.publicidad));
        super.onDestroy();
    }  

    public void botonPulsado(View vista) {

        if (vista.getId() == R.id.anadir) {
            startActivity(new Intent(this, AddActivity.class));
        }
        if (vista.getId() == R.id.listado) {
            startActivity(new Intent(this, ListadoActivity.class));
        }
        if (vista.getId() == R.id.expimp) {
           // startActivity(new Intent(this, ExpImpActivity.class));
            
            final CharSequence[] items = {getString(R.string.exp), getString(R.string.imp)};

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(getString(R.string.exp) + "/" + getString(R.string.imp));
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                    if (item==0){ //Enviar
                        iniciaExportacion();
                    }else{ //Recibir
                        iniciaImportacion();
                    }
                }
            });
           
            AlertDialog alert = builder.create();
            alert.show();
        }
        if (vista.getId() == R.id.ayuda) {
            startActivity(new Intent(this, Ayuda.class));
        }
        

    }
    public void iniciaExportacion(){
        startActivity(new Intent(this, ExpActivity.class));
    }
    
    public void iniciaImportacion(){
        startActivity(new Intent(this, ImpActivity.class));
    }
    
    public void cancelar() {
        finish();
    }

}
